package com.jic.product.controller.manage;


import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.product.common.util.BeanUtil;
import com.jic.product.entity.WarehouseFlowing;
import com.jic.product.manage.request.WarehouseFlowingRequest;
import com.jic.product.manage.response.WarehouseFlowingResponse;
import com.jic.product.service.WarehouseFlowingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/warehouseflowing")
@Api(value = "实体库存流水", description = "库存流水", tags = "库存管理")
public class WarehouseFlowingController {

    @Autowired
    private WarehouseFlowingService warehouseFlowing;


    /*
     * 分页查询
     * */
    @ApiOperation(value = "获取所有商品计量单位信息")
    @ResponseBody
    @PostMapping(value = "/queryPage")
    public RestResult<PageResult<WarehouseFlowingResponse>> queryPage(WarehouseFlowingRequest form) {
        Page page = new Page();
        page.setLimit(form.getLimit());
        page.setStart(form.getStart());
        WarehouseFlowing productUnits = BeanUtil.copy(form, WarehouseFlowing.class);
        PageResult<WarehouseFlowing> result = warehouseFlowing.queryPage(productUnits, page);
        List<WarehouseFlowingResponse> productUnitsResponseList = result.getRows().stream().map(temp -> {
            WarehouseFlowingResponse productUnitsResponse = BeanUtil.copy(temp, WarehouseFlowingResponse.class);
            return productUnitsResponse;
        }).filter(item -> item != null).collect(Collectors.toList());

        PageResult<WarehouseFlowingResponse> pageResult = new PageResult<>();
        pageResult.setRows(productUnitsResponseList);
        pageResult.setTotal(result.getTotal());
        return RestResult.success(pageResult);

    }

}
